package com.javaee.controller.user;

import com.javaee.entity.Board;
import com.javaee.entity.Doctor;
import com.javaee.service.admin.BoardService;
import com.javaee.service.user.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;


@Controller
public class IndexController {
    @Autowired
    IndexService indexService;
    @RequestMapping("/")
    public String goodDoctor(Model model){
        List<Doctor>doctors=indexService.showGoodDoctor();
        List<Board>boards=indexService.showBoard();
        model.addAttribute("doctors",doctors);
        model.addAttribute("boards",boards);
        return "index";
    }
    @GetMapping("/doctordetail/{id}")
    public String getDoctorDetail(
            @PathVariable(name = "id") int doctorId,
            Model model) {
        Doctor doctor = indexService.getDoctorById(doctorId);
        model.addAttribute("doctor", doctor);
        return "doctor/index-doctor";
    }
    @GetMapping("/boardDetail/{id}")
    public String getBoardDetail(
            @PathVariable(name = "id") int boardId,
            Model model) {
        Board boardDetail = indexService.getBoardById(boardId);
        model.addAttribute("boardDetail", boardDetail);
        return "aBoardDetails2";
    }

}
